package com.ruoyi.project.im.wechatlist.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.im.wechatlist.domain.Wechatlist;
import com.ruoyi.project.im.wechatlist.service.IWechatlistService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 公众号管理Controller
 * 
 * @author ruoyi
 * @date 2022-09-11
 */
@Controller
@RequestMapping("/im/wechatlist")
public class WechatlistController extends BaseController
{
    private String prefix = "im/wechatlist";

    @Autowired
    private IWechatlistService wechatlistService;

    @RequiresPermissions("im:wechatlist:view")
    @GetMapping()
    public String wechatlist()
    {
        return prefix + "/wechatlist";
    }

    /**
     * 查询公众号管理列表
     */
    @RequiresPermissions("im:wechatlist:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Wechatlist wechatlist)
    {
        startPage();
        List<Wechatlist> list = wechatlistService.selectWechatlistList(wechatlist);
        return getDataTable(list);
    }

    /**
     * 导出公众号管理列表
     */
    @RequiresPermissions("im:wechatlist:export")
    @Log(title = "公众号管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Wechatlist wechatlist)
    {
        List<Wechatlist> list = wechatlistService.selectWechatlistList(wechatlist);
        ExcelUtil<Wechatlist> util = new ExcelUtil<Wechatlist>(Wechatlist.class);
        return util.exportExcel(list, "公众号管理数据");
    }

    /**
     * 新增公众号管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存公众号管理
     */
    @RequiresPermissions("im:wechatlist:add")
    @Log(title = "公众号管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Wechatlist wechatlist)
    {
        return toAjax(wechatlistService.insertWechatlist(wechatlist));
    }

    /**
     * 修改公众号管理
     */
    @RequiresPermissions("im:wechatlist:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Wechatlist wechatlist = wechatlistService.selectWechatlistById(id);
        mmap.put("wechatlist", wechatlist);
        return prefix + "/edit";
    }

    /**
     * 修改保存公众号管理
     */
    @RequiresPermissions("im:wechatlist:edit")
    @Log(title = "公众号管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Wechatlist wechatlist)
    {
        return toAjax(wechatlistService.updateWechatlist(wechatlist));
    }

    /**
     * 删除公众号管理
     */
    @RequiresPermissions("im:wechatlist:remove")
    @Log(title = "公众号管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wechatlistService.deleteWechatlistByIds(ids));
    }
}
